home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
src.arc
/
FINGER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-13
|
2KB
|
73 lines
#include <stdio.h>
#include <string.h>
#include "global.h"
#include "mbuf.h"
#include "socket.h"
#include "session.h"
#include "proc.h"
#include "netuser.h"
int
dofinger(argc,argv,p)
int argc;
char *argv[];
void *p;
{
struct sockaddr_in sock;
char *cp;
int s,i;
struct mbuf *bp;
struct session *sp;
/* Allocate a session descriptor */
if((sp = newsession(argv[1],FINGER)) == NULLSESSION){
printf("Too many sessions\n");
freeargs(argc,argv);
return 1;
}
Current = sp;
Mode = CONV_MODE;
sp->cb.finger = Curproc;
sock.sin_family = AF_INET;
sock.sin_port = IPPORT_FINGER;
for(i=1;i<argc;i++){
cp = strchr(argv[i],'@');
if(cp == NULLCHAR){
printf("%s: local names not supported\n",argv[i]);
continue;
}
*cp++ = '\0';
printf("%s@%s -- ",argv[i],cp);
if((sock.sin_addr.s_addr = resolve(cp)) == 0){
printf("Host %s unknown\n",cp);
continue;
}
printf("trying %s",psocket((struct sockaddr *)&sock));
if((sp->s = s = socket(AF_INET,SOCK_STREAM,0)) == -1){
printf("Can't create socket\n");
break;
}
if(connect(s,(char *)&sock,sizeof(sock)) == -1){
cp = sockerr(s);
printf(" -- Connect failed: %s\n",cp != NULLCHAR ? cp : "");
close_s(s);
sp->s = -1;
continue;
}
printf("\n");
usprintf(s,"%s\r\n",argv[i]);
while(recv_mbuf(s,&bp,0,0,NULLCHAR,(int *)0) > 0){
/* Suspend output if we're not current */
while(Current != sp || Mode == CMD_MODE)
pwait(sp);
write_p(stdout,bp);
free_p(bp);
}
close_s(s);
sp->s = -1;
}
freeargs(argc,argv);
freesession(sp);
return 0;
}